package com.zm.demo.core.collection;

import org.junit.Test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.List;

import static java.lang.System.out;

/**
 * @author zoum
 * @create 2019/12/16 14:07
 */
public class HashMapTest {

    @Test
    public void test(){
        HashMap<String, String> hashMap1 = new HashMap<>();
        HashMap<String, String> hashMap = new HashMap<>(10);
//        HashMap<Integer, Integer> hashMap1 = new HashMap<>(10000);
//        for (int i = 0; i < 15000; i++) {
//            hashMap1.put(i,i);
//        }
//        hashMap.put("1","1");
//        out.println(hashMap1.size());
//        out.println(hashMap1.toString());
    }

    @Test
    public void test1(){
        int c = 100;
        int n = c - 1;
        // 0100 0010
        out.println(4|7);
        n |= n >>> 1;
        out.println("1==" + n);
        n |= n >>> 2;
        out.println("2==" + n);
        n |= n >>> 4;
        out.println("4==" + n);
        n |= n >>> 8;
        out.println("8==" + n);
        n |= n >>> 16;
        out.println("16==" + n);

        out.println((n < 0) ? 1 : (n >= Integer.MAX_VALUE) ? Integer.MAX_VALUE : n + 1);
    }

    @Test
    public void testReduce(){
        Map<String,String> map = new HashMap<>();
        map.put("1","1");
        map.keySet().stream().forEach(k -> map.put("-" + k, map.get(k)));
        out.println(map);
    }

    @Test
    public void testMapUpdate(){
        Map<String, List<String>> map = new HashMap<>();
        map.put("1",new ArrayList<>());
        List<String>list1 = map.get("1");
        list1.add("1");
        list1.add("2");
        out.println(map);
    }

    @Test
    public void testMapGetNull(){
        Map<String, List<String>> map = new HashMap<>();

        out.println(map.get("121212"));
        out.println(map.get("121212").equals("1"));
    }
}
